<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>作用域插槽使用案例</title>
</head>
<body>
<div id="app">
    <cpn></cpn>
    <hr>
    <cpn>
        <template v-slot="scope">
            <div>{{ scope.data }}</div>
        </template>
    </cpn>

    <hr>
    <cpn>
        <template v-slot="scope">
            <span>{{ scope.data.join(' - ') }}</span>
        </template>
    </cpn>
</div>

<template id="cpn">
    <slot v-bind:data="movies">
        <ul>
            <li v-for="item in movies">{{ item }}</li>
        </ul>
    </slot>
</template>

<script type="module">
    import {createApp, reactive, defineComponent} from "../../../js/vue.esm-browser.js";

    let component = defineComponent(
        {
            template: "#cpn",
            setup() {
                let movies = reactive(
                    ['霸王别姬', "夜半歌声", '纵横四海']
                )
                return {
                    movies,
                };
            }
        }
    );

    let app = createApp(
        {
            setup() {
                return {}
            }
        }
    );

    app.component("cpn", component)

    app.mount("#app")
</script>
</body>
</html>